package ru.chaykin;

import javax.swing.JLabel;
import javax.swing.SwingWorker;

import com.codeminders.hidapi.HIDDevice;

public class DataTransferWorker extends SwingWorker<String, String> {
	
	private JLabel label;
	private byte[] buf;
	
	public DataTransferWorker(JLabel label) {
		this.label = label;
	}

	@Override
	protected String doInBackground() throws Exception {
		HIDDevice device = HID.getHIDDevice();
		buf = new byte[4];
		int readed;
		try {
			device.disableBlocking();
			buf[0] = 5;
			readed = device.getFeatureReport(buf);
		}
		catch (Exception e) {
			throw new Exception();
		}
		String res = "";
		for (int i = 0; i < buf.length; i++) {
			res += buf[i] + " ";
		}
		return res;
	}
	
	@Override
    protected void done() {
		String res = "";
		for (int i = 0; i < buf.length; i++) {
			res += buf[i] + " ";
		}
        label.setText(res);
    }
}
